package org.springframework.core.type.classreading;

import java.util.ArrayList;
import java.util.List;

import org.springframework.asm.MethodVisitor;

/**
 * 这个类代理了原来的{@link AnnotationMetadataReadingVisitor}
 * @author jackson
 *
 */
public class ImplementClassMetadataReadingVisitor extends ProxyClassMetadataReadingVisitor{

	final List<ImplementMethodMetadataReadingVisitor> methods;
	ImplementClassMetadataReadingVisitor parentMetadata;
	public ImplementClassMetadataReadingVisitor(ClassLoader classLoader) {
		super(classLoader);
		this.methods = new ArrayList<ImplementMethodMetadataReadingVisitor>();
	}
	
	public void fillMethods(List<ImplementMethodMetadataReadingVisitor> methods){
		methods.addAll(methods);
		if(null != parentMetadata){
			parentMetadata.fillMethods(methods);
		}
	}
	
	public void setParentMetadata(ImplementClassMetadataReadingVisitor parentMetadata) {
		this.parentMetadata = parentMetadata;
	}

	@Override
	public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
		MethodMetadataReadingVisitor mv = (MethodMetadataReadingVisitor)proxy.visitMethod(access, name, desc, signature, exceptions);
		if(isAbstract()){//只处理虚父类
			methods.add(new ImplementMethodMetadataReadingVisitor(mv, access, desc, signature, exceptions));
		}
		return mv;
	}
}
